﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Wuqi.Webdiyer;
using ncp.Business;
using ncp.Business.Common;

namespace ncp.Web.member
{
    public partial class comment : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var userInfo = WebMasterCookie.GetCookie();
            if (userInfo == null)
            {
                Response.Redirect("/login.aspx");
            }
            if (!IsPostBack)
            {
                var role = Request.QueryString["role"];
                if (role == "my")
                {
                    lbTitle.Text = "我的评论";
                    AspNetPager1.RecordCount = CommentInfoBll.GetCommentInfoCount("msgclient_Id=" + userInfo.Id + " and Comment_Status=1 ", CommonConst.DB_Name);
                }
                else if (role == "index")
                {
                    AspNetPager1.RecordCount = CommentInfoBll.GetCommentInfoCount("Client_Id=" + userInfo.Id + " and Comment_Status=1", CommonConst.DB_Name);
                }
                else
                {
                    Response.Redirect("/shop/error.html");
                }
            }
        }
        //绑定求购信息
        private void BindAllNews()
        {
            var userInfo = WebMasterCookie.GetCookie();
            Dictionary<string, object> dicHot = new Dictionary<string, object>();
            var role = Request.QueryString["role"];
            if (role == "my")
            {
                dicHot.Add("msgclient_Id", userInfo.Id);
            }
            else
            {
                dicHot.Add("Client_Id", userInfo.Id);
            }
            dicHot.Add("Comment_Status", 1);
            var pageIndex = AspNetPager1.CurrentPageIndex - 1;
            var pageSize = AspNetPager1.PageSize;
            string orderBy = " Comment_Date desc";
            var dt = CommentInfoBll.GetCommentInfoTable(pageIndex, pageSize, "*", orderBy, dicHot, CommonConst.DB_Name);
            repMsg.DataSource = dt;
            repMsg.DataBind();
        }

        protected void AspNetPager1_PageChanged(object src, EventArgs e)
        {
            BindAllNews();
        }
    }
}
